import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

//引入vuex
import Vuex from 'vuex'
//注册
Vue.use(Vuex)
//实例化仓库
const store = new Vuex.Store({
  //严格模式
  strict:true,
  state:{
    username:'小红',
    age:18,
    student:{
      name:'小红',
      age:18,
      school:{
        name:'黑马程序员',
        address:{
          city:'广州',
          detail:'珠吉街道'
        }
      }
    }
  },
  mutations:{
    addage(state,data){
      state.age += data
    },
    aa(){
      console.log('根模块');
    }
  },
  actions:{
    //自带store仓库
   asyncadd(store,data){
      setTimeout(() => {
        store.commit('addage', data)
      }, 1000);
   }
  },
  getters:{
    address(state){
      return state.student.school.address.detail
    }
  },


  //modules
  modules:{
    user:{
      namespaced: true,
      state: {
        token:'123456'
      },
      mutations:{
        
        aa(){
          console.log('user模块');
        }
      }
    },
    setting:{
      // namespaced: true,
      state: {
        name:'积极'
      },
      mutations:{
        
        aa(){
          console.log('setting模块');
        }
      }
    }
  }
})
//挂载

new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
